{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "sys.version_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/javascript": "\n                    window.jupyter_python_executable = '\\r\\r';\n                    window.jupyter_widget_checks_silent = true;\n                    window.jupyter_widget_checks_libraries = [{\"python\": \"ipyvuetify\", \"classic\": \"jupyter-vuetify/extension\", \"lab\": \"jupyter-vuetify\"}, {\"python\": \"ipyvue\", \"classic\": \"jupyter-vue/extension\", \"lab\": \"jupyter-vue\"}];\n                    ",
      "text/plain": [
       "<IPython.core.display.Javascript object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div class=\"jupyter-widget-checks-container\">\n",
       "    <script>\n",
       "        (function () {\n",
       "            console.log(\"Checking for jupyter-widgets extensions\")\n",
       "            const inLab = window._JUPYTERLAB !== undefined;\n",
       "            const silent = jupyter_widget_checks_silent;\n",
       "            const containers = document.getElementsByClassName('jupyter-widget-checks-container');\n",
       "            const rootEl = containers[containers.length - 1];\n",
       "            const libraries = window.jupyter_widget_checks_libraries;\n",
       "\n",
       "            function getBaseUrl() {\n",
       "                const labConfigData = document.getElementById(\"jupyter-config-data\");\n",
       "                if (labConfigData) {\n",
       "                    /* lab and Voila */\n",
       "                    return JSON.parse(labConfigData.textContent).baseUrl;\n",
       "                }\n",
       "                let base = document.body.dataset.baseUrl || document.baseURI;\n",
       "                return base;\n",
       "            }\n",
       "\n",
       "            function checkLibrary(extensions, library) {\n",
       "                let installed = false;\n",
       "                let ok = true;\n",
       "                if (inLab) {\n",
       "                    installed = _JUPYTERLAB[library.lab] !== undefined\n",
       "                } else {\n",
       "                    installed = extensions[library.classic] !== undefined;\n",
       "                    let enabled = extensions[library.classic] === true;\n",
       "                }\n",
       "                const div = document.createElement(\"div\")\n",
       "                if (installed) {\n",
       "                    if (!silent) {\n",
       "                        div.innerHTML = `Extension ${library.python} is installed at the server ✅`\n",
       "                        rootEl.appendChild(div)\n",
       "                    }\n",
       "                } else {\n",
       "                    div.innerHTML = `Extension ${library.python} is <b>NOT</b> installed at the server ❌.`\n",
       "                    rootEl.appendChild(div)\n",
       "                    ok = false;\n",
       "                }\n",
       "                return ok;\n",
       "            }\n",
       "\n",
       "            async function check() {\n",
       "                const url = `${getBaseUrl()}api/config/notebook`\n",
       "                const response = (await fetch(url));\n",
       "                const data = await response.json()\n",
       "                const extensions = data[\"load_extensions\"];\n",
       "                var ok = true;\n",
       "                let needsInstall = [];\n",
       "                libraries.forEach((library) => {\n",
       "                    if (!checkLibrary(extensions, library)) {\n",
       "                        ok = false;\n",
       "                        needsInstall.push(library.python)\n",
       "                        console.log(\"Needs install\", library.python)\n",
       "                    }\n",
       "                })\n",
       "                console.log(ok, needsInstall)\n",
       "                if (!ok) {\n",
       "                    const div = document.createElement(\"div\")\n",
       "                    const div2 = document.createElement(\"div\")\n",
       "                    div.innerHTML = `Run <code>${jupyter_python_executable} -m pip install ${needsInstall.join(\" \")}</code>. Refresh the page after installation.`\n",
       "                    div2.innerHTML = `Visit <a href=\"https://solara.dev/documentation/getting_started/troubleshoot\" target=\"_blank\">https://solara/dev/documentation/getting_started/troubleshoot</a> for more information.`\n",
       "                    rootEl.appendChild(div)\n",
       "                    rootEl.appendChild(div2)\n",
       "                }\n",
       "            }\n",
       "            check()\n",
       "        })();\n",
       "    </script>\n",
       "</div>\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from mesa.examples import WolfSheep"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from mesa.examples.advanced.wolf_sheep import app\n",
    "from mesa.experimental.devs import ABMSimulator"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "simulator = ABMSimulator()\n",
    "model = WolfSheep(seed=10,simulator=simulator)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "model.datacollector.collect(model)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "ename": "UserWarning",
     "evalue": "No agent reporters have been defined in the DataCollector, returning empty DataFrame.",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mUserWarning\u001b[0m                               Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[9], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mmodel\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdatacollector\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_agent_vars_dataframe\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mD:\\workspace\\QGIS\\apps\\Python312\\Lib\\site-packages\\mesa\\datacollection.py:342\u001b[0m, in \u001b[0;36mDataCollector.get_agent_vars_dataframe\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m    340\u001b[0m \u001b[38;5;66;03m# Check if self.agent_reporters dictionary is empty, if so raise warning\u001b[39;00m\n\u001b[0;32m    341\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39magent_reporters:\n\u001b[1;32m--> 342\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mUserWarning\u001b[39;00m(\n\u001b[0;32m    343\u001b[0m         \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mNo agent reporters have been defined in the DataCollector, returning empty DataFrame.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m    344\u001b[0m     )\n\u001b[0;32m    346\u001b[0m all_records \u001b[38;5;241m=\u001b[39m itertools\u001b[38;5;241m.\u001b[39mchain\u001b[38;5;241m.\u001b[39mfrom_iterable(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_agent_records\u001b[38;5;241m.\u001b[39mvalues())\n\u001b[0;32m    347\u001b[0m rep_names \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mlist\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39magent_reporters)\n",
      "\u001b[1;31mUserWarning\u001b[0m: No agent reporters have been defined in the DataCollector, returning empty DataFrame."
     ]
    }
   ],
   "source": [
    "model.datacollector.get_agent_vars_dataframe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "simulator.run_for(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "simulator.event_list.peak_ahead(0)[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = model.datacollector.get_model_vars_dataframe()\n",
    "print(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "model.datacollector.get_agent_vars_dataframe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "model.step()\n",
    "data = model.datacollector.get_model_vars_dataframe()\n",
    "print(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
